/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pds_facebook;

import com.restfb.Connection;
import com.restfb.FacebookClient;
import com.restfb.types.Post;
import com.restfb.types.User;
import java.util.List;
import pds_facebook.Adapter.FriendAdapter;
import pds_facebook.Adapter.MyFriend;

/**
 *
 * @author Joao Classe destinada a impressão de informações coletadas
 */
public class DataPrinter {

    //imprime as informações pessoais
    public static void printPersonalData(String name, FacebookClient facebookClient) {

        User user = facebookClient.fetchObject(name, User.class);

        System.out.println("\nUser name: " + user.getName());

        System.out.println("Birthday: " + user.getBirthday());
        System.out.println("Education: " + user.getEducation().get(0).getSchool().getName());
        System.out.println("Gender: " + user.getGender());
        System.out.println("Relationship: " + user.getRelationshipStatus());
        System.out.println("Sports: " + user.getSports().get(0).getName());

        for (int i = 0; i < user.getLanguages().size(); i++) {
            if (user.getLanguages() != null) {
                System.out.println("Languages: "
                        + user.getLanguages().get(i).getName());
            } else {
                System.out.println("Languages: No data about this person");
            }
        }
        System.out.println("Interested in: " + user.getInterestedIn());
    }

    //imprime as informações pessoais públicas dos amigos
    public static void printFriendsData(String name, FacebookClient facebookClient) {

        Connection<User> myFriends = facebookClient.fetchConnection(name + "/friends", User.class);

        System.out.println("Count of my friends: " + myFriends.getData().size());
        System.out.println("\nDATA OF MY FRIENDS");

        int counter = 0;

        while (myFriends.hasNext()) {

            String idpass = myFriends.getData().get(counter).getId();
            User user2 = facebookClient.fetchObject(idpass, User.class);

            System.out.println("\nUser name: " + user2.getName());
            if (user2.getBirthday() != null) {
                System.out.println("Birthday: " + user2.getBirthday());
            } else {
                System.out.println("Birthday: No data about this person");
            }


            if (user2.getGender() != null) {
                System.out.println("Gender: " + user2.getGender());
            } else {
                System.out.println("Gender: No data about this person");
            }
            //Some itens to fix:

            for (int i = 0; i < user2.getEducation().size(); i++) {
                if (user2.getEducation() != null) {
                    System.out.println("Education: "
                            + user2.getEducation().get(i).getSchool().getName());
                } else {
                    System.out.println("Educatiton: No data about this person");
                }
            }

            if (user2.getRelationshipStatus() != null) {
                System.out.println("Relationship: "
                        + user2.getRelationshipStatus());
            } else {
                System.out.println("Relationship: No data about this person");
            }

            for (int i = 0; i < user2.getLanguages().size(); i++) {
                if (user2.getLanguages() != null) {
                    System.out.println("Languages: "
                            + user2.getLanguages().get(i).getName());
                } else {
                    System.out.println("Languages: No data about this person");
                }
            }

            for (int i = 0; i < user2.getSports().size(); i++) {
                if (user2.getSports() != null) {
                    System.out.println("Sports: "
                            + user2.getSports().get(i).getName());
                } else {
                    System.out.println("Sports: No data about this person");
                }
            }
            System.out.println("\n-------------------------------------------------------------");

            counter++;
        }
    }

    public static void printMyFeed(String name, FacebookClient facebookClient) {
        Connection<Post> myFeed = facebookClient.fetchConnection(name + "/feed", Post.class);

        System.out.println("First item in my feed: " + myFeed.getData().get(0).getName());
        System.out.println("My last feeds:");

        for (List<Post> myFeedConnectionPage : myFeed) {
            for (Post post : myFeedConnectionPage) {
                System.out.println("Post: " + post.getName());
            }
        }
    }

    // Não funciona, lança excessão de responabilidade de acesso
    public static void printMyfriendFriend(String name, FacebookClient facebookClient) {

        Connection<User> myFriends = facebookClient.fetchConnection(name + "/friends", User.class);

        String idpass = myFriends.getData().get(0).getId();
        User user2 = facebookClient.fetchObject(idpass, User.class);

        Connection<User> myFriends2 = facebookClient.fetchConnection(idpass + "/friends", User.class);

        String idpass2 = myFriends2.getData().get(0).getId();
        User user3 = facebookClient.fetchObject(idpass2, User.class);
        System.out.println(user3.getName());
    }
}
